package cn.java.Concurrency.fork;

import java.util.concurrent.RecursiveAction;

/**
 * @author 小石潭记
 * @date 2021/12/19 20:15
 * @Description: ${todo}
 */
public class MyRecursiveAction extends RecursiveAction {

    private int beginValue;
    private int endValue;

    public MyRecursiveAction(int beginValue, int endValue) {
        this.beginValue = beginValue;
        this.endValue = endValue;
    }

    @Override
    protected void compute() {
        System.out.println(Thread.currentThread().getName() + "--------");
        if (endValue - beginValue > 2) {
            int middelNum = (beginValue + endValue) / 2;
            MyRecursiveAction leftAction = new MyRecursiveAction(beginValue, middelNum);
            MyRecursiveAction rightAction = new MyRecursiveAction(middelNum + 1, endValue);
            this.invokeAll(leftAction, rightAction);
        } else {
            System.out.println("打印组合为： " + beginValue + " " + endValue);
        }
    }
}
